package com.chanyachting.emall.domain;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

import org.apache.commons.beanutils.BeanUtils;

import com.chanyachting.emall.dao.AdDAO;
import com.chanyachting.emall.domain.base.BaseAd;

/**
 * This is the object class that relates to the ad table.
 * Any customizations belong here.
 */
public class Ad extends BaseAd {

/*[CONSTRUCTOR MARKER BEGIN]*/
	public Ad () {
		super();
	}

	/**
	 * Constructor for primary key
	 */
	public Ad (java.lang.Integer _id) {
		super(_id);
		
		Ad ad=(Ad)new AdDAO().load(Ad.class, _id);
		
		if(ad!=null){
			
			try {
				BeanUtils.copyProperties(this, ad);
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
		
	}

	/**
	 * Constructor for required fields
	 */
	public Ad (
		java.lang.Integer _id,
		java.lang.String _summary,
		java.lang.String _type,
		java.lang.String _pageUrl,
		java.lang.String _createDate,
		java.lang.Integer _clickNumber) {

		super (
			_id,
			_summary,
			_type,
			_pageUrl,
			_createDate,
			_clickNumber);
	}
/*[CONSTRUCTOR MARKER END]*/
	
	
	public static List list(){
		
		return new AdDAO().find("from Ad");
	}
	
	public boolean save(){
		
		new AdDAO().save(this);
		
		return true;
	}
	
	
	public boolean update(){
		
		new AdDAO().update(this);
		
		return true;
	}
	
	
	public boolean delete(){
		
		new AdDAO().delete(this);
		
		return true;
	}
	
}